package com.spic.business.blast.controller;

import com.spic.business.blast.domain.BlastDeploymentWeigh;
import com.spic.business.blast.domain.vo.StatisticsWeighInfoVo;
import com.spic.business.blast.service.IBlastDeploymentWeighService;
import com.spic.business.common.datascope.anotation.BusinessDataScope;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 称重信息Controller
 *
 * @author spic
 * @date 2022-03-09
 */
@RestController
@RequestMapping("/weigh")
public class BlastDeploymentWeighController extends BaseController
{
    @Autowired
    private IBlastDeploymentWeighService blastDeploymentWeighService;

    /**
     * 查询称重信息列表
     */
    @PreAuthorize(hasPermi = "blast:weigh:list")
    @BusinessDataScope(menuPath = "business/blastDeployment/weigh/index")
    @GetMapping("/list")
    public TableDataInfo list(BlastDeploymentWeigh blastDeploymentWeigh)
    {
        startPage();
        List<BlastDeploymentWeigh> list = blastDeploymentWeighService.selectBlastDeploymentWeighList(blastDeploymentWeigh);
        return getDataTable(list);
    }
    @PreAuthorize(hasPermi = "blast:weigh:statistics")
    @GetMapping("/statisticsWeigh/info")
    public TableDataInfo getStatisticsWeighInfo(BlastDeploymentWeigh blastDeploymentWeigh){
        startPage();
        List<StatisticsWeighInfoVo> list = blastDeploymentWeighService.selectstatisticsWeighInfo(blastDeploymentWeigh);
        return getDataTable(list);
    }
    /**
     * 导出称重信息列表
     */
    @PreAuthorize(hasPermi = "blast:weigh:export")
    @Log(title = "称重信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlastDeploymentWeigh blastDeploymentWeigh) throws IOException
    {
        List<BlastDeploymentWeigh> list = blastDeploymentWeighService.selectBlastDeploymentWeighList(blastDeploymentWeigh);
        ExcelUtil<BlastDeploymentWeigh> util = new ExcelUtil<BlastDeploymentWeigh>(BlastDeploymentWeigh.class);
        util.exportExcel(response, list, "称重信息数据");
    }

    /**
     * 获取称重信息详细信息
     */
    @PreAuthorize(hasPermi = "blast:weigh:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(blastDeploymentWeighService.selectBlastDeploymentWeighById(id));
    }

    /**
     * 新增称重信息
     */
    @PreAuthorize(hasPermi = "blast:weigh:add")
    @Log(title = "称重信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlastDeploymentWeigh blastDeploymentWeigh)
    {
        return blastDeploymentWeighService.insertBlastDeploymentWeigh(blastDeploymentWeigh);
    }

    /**
     * 修改称重信息
     */
    @PreAuthorize(hasPermi = "blast:weigh:edit")
    @Log(title = "称重信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlastDeploymentWeigh blastDeploymentWeigh)
    {
        return toAjax(blastDeploymentWeighService.updateBlastDeploymentWeigh(blastDeploymentWeigh));
    }

    /**
     * 删除称重信息
     */
    @PreAuthorize(hasPermi = "blast:weigh:remove")
    @Log(title = "称重信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(blastDeploymentWeighService.deleteBlastDeploymentWeighByIds(ids));
    }

    @GetMapping("/getWeighInfo")
    public AjaxResult getWeighInfo(BlastDeploymentWeigh blastDeploymentWeigh){
        BlastDeploymentWeigh weighInfo = blastDeploymentWeighService.getWeighInfo(blastDeploymentWeigh);
        return AjaxResult.success(weighInfo);
    }
    @GetMapping("/alarm")
    public AjaxResult getWeighAlarm(){
        return AjaxResult.success(blastDeploymentWeighService.getWeighAlarm());
    }
}
